// mytime3.cpp -- implementing Time methods
#include <iostream>
#include "mytime3.h"

Time::Time(int hours, int minutes)
{
    _hours = hours;
    _minutes = minutes;
}

void Time::AddHour(int hours)
{
    _hours += hours;
}

void Time::AddMin(int minutes)
{
    _minutes += minutes;
    _hours = _hours + _minutes / 60;
    _minutes %= 60;
}

void Time::Reset(int hours, int minutes)
{
    _hours = hours;
    _minutes = minutes;
}

Time Time::operator+(const Time & t) const
{
    Time sum;
    sum._minutes =  _minutes + t._minutes;
    sum._hours = _hours + t._hours + sum._minutes / 60;
    sum._minutes %= 60;

    return sum;
}

Time Time::operator-(const Time & t) const
{
    Time diff;
    int total1 = t._minutes + t._hours * 60;
    int total2 = _minutes + _hours * 60;
    diff._minutes = (total2 - total1) % 60;
    diff._hours = (total2 - total1) / 60;

    return diff;
}

Time Time::operator*(double multi) const
{
    Time result;

    long total_minutes = _hours * 60 * multi + _minutes * multi;

    result._minutes = total_minutes % 60;
    result._hours = total_minutes / 60;

    return result;
}

std::ostream & operator<<(std::ostream & os, const Time & t)
{
    os << t._hours << " hours. " << t._minutes << " minutes";
    return os;
}